<?php
/**
 * 店铺控制器
 * @version 1.0
 * @author ezhu <ezhu@jipukeji.com>
 */

namespace Shop\Controller;

use Common\Api\UserApi;

class StoreController extends CommonController{
    
    /**
     * 构造函数
     */
    protected function _initialize(){
        parent::_initialize();
        $this->assign('user', $this->user);
        $this->assign('member', $this->member);
    }
    
    
    /**
     * 商店后台首页
     */
    public function index(){
        $map['store_id'] = $this->store_id;
        $map['status'] = 1;
        $data = D('Store')->getInfo($map);
        $data['grade_name'] = M('store_grade')->where(array('id'=>$data['grade_id']))->getField('name');
        //统计信息
        $stat = A('Store','Event')->stat($this->store_id);
        // 图表统计
        $stat['chartData'] = D('Stat')->getOrderChartData($this->store_id);
        // 店铺余额
        $amount = A('Store','Event')->finance($this->store_id);
        // 信息未读取条数
        $unReadMsg = A('Store','Event')->unReadMsg($this->store_id);
        // 店铺消息
        $msgMap = array(
            'store_id' => $this->store_id,
            'type'     => I('get.type', 'all'),
            'limit'    => 3
        );
        $message = A('Store', 'Event')->msgLists($msgMap);
        $this->assign('message',$message);
        $this->assign('unReadMsg',$unReadMsg);
        $this->assign('amount',$amount);
        $this->assign('stat',$stat);
        $this->assign('data',$data);
        $this->assign('sign','index');
        $this->display();
    }
    
    
    /**
     * 店铺库存警报
     */
    public function warning(){
        $map['store_id'] = $this->store_id;
        if(IS_POST && IS_AJAX){
            $data['storage_alarm'] = I('alarm');
            $rst = M('Store')->where($map)->save($data);
            if($rst !== false){
                $this->success('设置成功！');
            }else{
                $this->error('设置失败！');
            }
            exit;
        }
        $store = D('Store')->getInfo($map);
        $this->assign('data',$store);
        $this->display();
    }
    
    
    /**
     * 店铺设置
     */
    public function set(){
        $id = I('id');
        $model = D('Store');
        $map['store_id'] = $this->store_id;
        $map['status'] = 1;
        if(IS_POST && IS_AJAX){
            $hotline = I('post.hot-line','');
            if(isset($hotline) && $hotline){
                $isMob="/^1[3-8]{1}[0-9]{9}$/";
                $isTel="/^([0-9]{3,4}-)?[0-9]{7,8}$/";
                $isTel_400 = "/^400(-\d{3,4}){2}$/";    //验证400固话号码
                if(!preg_match($isMob,$hotline) && !preg_match($isTel,$hotline) && !preg_match($isTel_400,$hotline))
                {
                    $this->error("请填写正确的手机号码或固定电话");
                    exit;
                }
            }
            if($model->create()){
                $rst = $model->where($map)->save();
                $rst !== false ? $this->success('修改成功',U('Shop/Store/index')) : $this->error('修改失败');
            }else{
                $this->error($model->getError());
            }
            exit;
        }
        
        $data = $model->getInfo($map);
        $data['grade_name'] = M('StoreGrade')->where(array('id'=>$data['grade_id']))->getField('name');
        
        // 发货地址
        $addMap['store_id'] = $this->store_id;
        $addOrder = '`is_default` DESC';
        $addLists = $this->lists(M('StoreAddress'), $addMap,$addOrder);
        
        $this->assign('meta_title','店铺设置');
        $this->assign('addLists',$addLists);
        $this->assign('data',$data);
        $this->display();
    }
    
    
    /**
     * 店铺轮播图/幻灯片
     */
    public function slide(){
        $model = D('StoreBanner');
        $map['store_id'] = $this->store_id;
        $map['status'] = 1;
        $type =1;
        $map['type'] = $type;
        $order = 'sort ASC';
       //dump($type);
        $lists = $model->order($order)->where($map)->select();
       // dump($lists);
        // $slide = explode(',',$store['slides']);
        // $url = explode(',',$store['slides_url']);
        /*   $lists = array();
           foreach ($slide as $key=>$val){
               $lists[$key]['slide'] = $val;
               $lists[$key]['url'] = $url[$key];
           }*/
        $this->assign('meta_title','幻灯片');
        $this->assign('lists',$lists);
        $this->assign('type',$type);
        $this->display();
    }

    /**
     * 店铺手机轮播图/幻灯片
     */
    public function slides(){
        $model = D('StoreBanner');
        $map['store_id'] = $this->store_id;
        $map['status'] = 1;
        $type =2;
        $map['type'] = $type;
        $order = 'sort ASC';
        $lists = $model->where($map)->order($order)->select();
        $this->assign('meta_title','幻灯片');
        $this->assign('lists',$lists);
        $this->assign('type',$type);
        $this->display('slide');
    }


    /**
     * 轮播设置排序
     */
    public function slideOrder(){
        $slide = I('id');
        $slideUrl = I('url');
        if(empty($slide) || empty($slideUrl)){
            $this->error('参数错误');
        }
        $model = D('Store');
        $map['store_id'] = $this->store_id;
        $map['status'] = 1;
        $data['slide'] = $slide;
        $data['slide_url'] = $slideUrl;
        $rst = $model->where($map)->save($data);
        $rst !== false ? $this->success('修改成功',U('Shop/Store/slide')) : $this->error('修改失败');
        exit;
    }

    public function setFieldValue(){
        $id = I('post.id', '');
        $field = I('post.field', '');
        $value = I('post.value', '');
        if(empty($id) || empty($field)){
            $this->error('参数不完整！');
        }
        if(!check_form_hash()){
            $this->error('非法数据提交！');
        }

        $res = M('StoreBanner')->where(array('id'=>$id))->setField($field, $value);
        if($res){
            $this->success('更新成功！');
        }else{
            $this->error('更新失败！');
        }
    }
    
    
    /**
     * 编辑幻灯片
     */
    public function editSlide(){
        $id = I('id');
        $type = I('type');
        if(!isset($_REQUEST['id'])){
            $this->error('参数错误');
        }
        $model = D('StoreBanner');
        $map['store_id'] = $this->store_id;
        $store_id = $this->store_id;
        $map['status'] = 1;
        $map['id'] = $id;
        if(IS_POST && IS_AJAX){
            $data = I('post.');
            $pic = I('slide');
            $jump = I('url');
           if(empty($pic)){
               $this->error('请上传轮播图');
           }
           
            $data['slide'] = $pic;
            $data['slide_url'] = $jump;
            $data['store_id'] = $store_id;
            Cookie('__forwards__', $_SERVER['HTTP_REFERER']);
            if($data['id']){
                $rst = M('StoreBanner')->where($map)->save($data);
                if($rst !== false){
                  $type == 1 ? $this->success('修改成功', U('Shop/Store/slide')) : $this->success('修改成功', U('Shop/Store/slides'));
               }else{
                   $this->error('修改失败');
               }
                //$rst  ? $this->success('修改成功', U('Shop/Store/slide?type='.$type)) : $this->error('修改失败');
            }else {
                $rst = M('StoreBanner')->add($data);
                if($rst !== false){
                    $type == 1 ? $this->success('添加成功', U('Shop/Store/slide')) : $this->success('添加成功', U('Shop/Store/slides'));
                }else{
                    $this->error('添加失败');
                }
            }
        }
        $lists = $model->where($map)->find();
        $this->assign('meta_title','幻灯片');
        $this->type = $type;
        $this->assign('id',$id);
        $this->assign('lists',$lists);
        $this->display();
    }

    /**
     * 删除幻灯片
     */
    public function setStatus(){
        $id = I('id');
        $type = I('type');
       // dump($type);die;
        $rst = M('StoreBanner')->where(array('id'=>$id))->setField('status',0);
        if($type == 1){
            $rst !== false ? $this->success('删除成功', U('Shop/Store/slide')) : $this->error('删除失败');
        }else{
            $rst !== false ? $this->success('删除成功', U('Shop/Store/slides')) : $this->error('删除失败');
        }
    }



    /**
     * 店铺导航列表
     */
    public function nav(){
        $map['store_id'] = $this->store_id;
        $lists = $this->lists('StoreNav',$map);
        $this->assign('meta_title','店铺导航');
        $this->assign('lists',$lists);
        $this->display();
    }
    
    
    /**
     * 编辑、新增卖家导航
     */
    public function editNav(){
        $id = I('request.id');
        $map['id'] = $id;
        $map['store_id'] = $this->store_id;
        $model = M('StoreNav');
        if(IS_POST && IS_AJAX){
            $data['id'] = $id;
            $data['store_id'] = $this->store_id;
            $data['title'] = I('title');
            $data['is_show'] = I('is_show');
            $data['url'] = I('url');
            $data['new_open'] = I('new_open');
            empty($data['title']) && $this->error('请填写导航名称');
    
            if(!empty($id)){
                $type = '编辑';
                $rst = $model->where($map)->save($data);
            }else{
                $type = '添加';
                $data['ctime'] = time();
                $rst = $model->add($data);
            }
            $rst !== false ? $this->success($type.'成功！',U('nav')) : $this->error($type.'失败！');
        }
        $data = array();
        $meta_title = '添加导航';
        if($id){
            $data = $model->where($map)->find();
            $meta_title = '编辑导航';
        }
        $this->assign('data',$data);
        $this->assign('meta_title',$meta_title);
        $this->display();
    }
    
    
    /**
     * 删除商户导航
     */
    public function delNav(){
        $id = I('request.ids');
        if(empty($id)){
            $this->error('请选择要操作的对象');
        }
        $map['id'] = array('in',$id);
        $map['store_id'] = $this->store_id;
        $rst = M('StoreNav')->where($map)->delete();
        $rst ? $this->success('成功删除') : $this->error('删除失败！');
    }
    
    
    /**
     * 店铺信息查看（申请入驻时填写的信息）
     */
    public function info(){
        $seller_user = session('seller_user');
        $member_id = $seller_user['member_id'];
        $data = D('Store')->info($member_id);
        //数据处理
        
        Cookie('__forward__', $_SERVER['REQUEST_URI']);
        $this->meta_title = '店铺信息';
        $this->assign('data',$data);
        $this->display();
    }
    
    
    /**
     * 店铺分类管理--TODO：待定
     */
    public function storeClass(){
        $tree = D('Store')->storeClass($this->store_id,'id,pid,name,store_id,sort,status');
        $this->assign('tree', $tree);
        //记录当前列表页的Cookie
        Cookie('__forward__', $_SERVER['REQUEST_URI']);
        C('_SYS_GET_CATEGORY_TREE_', true); //标记系统获取分类树模板
        $this->meta_title = '商品分类管理';
        $this->display();
    }
    
    
    /**
     * 显示分类树，仅支持内部调
     * @param  array $tree 分类树
     * @author Max.Yu <max@jipu.com>
     */
    public function tree($tree = null){
        C('_SYS_GET_CATEGORY_TREE_') || $this->_empty();
        $this->assign('tree', $tree);
        $this->display('tree');
    }
    
    
    /**
     * 添加、修改店铺分类
     */
    public function editClass(){
        $id = I('request.id');
        $pid = I('request.pid');
        $status = I('status');
        $map['id'] = $id;
        $map['status'] = array('egt',0);
        $map['store_id'] = $this->store_id;
        $model = M('StoreClass');
        if(IS_POST && IS_AJAX){
            $data['id'] = $id;
            $pid && $data['pid'] = $pid;
            $data['store_id'] = $this->store_id;
            $data['name'] = I('name');
            $data['sort'] = I('sort');
            isset($_POST['status']) && $data['status'] = $status;
            empty($data['name']) && $this->error('请填写分类名称');
            if(!empty($id)){
                $type = '编辑';
                $rst = $model->where($map)->save($data);
            }else{
                $type = '添加';
                $rst = $model->add($data);
            }
            $rst !== false ? $this->success($type.'成功！',U('storeClass')) : $this->error($type.'失败！');
        }
        $data = array();
        $meta_title = '添加分类';
        
        if($id){
            $data = $model->where($map)->find();
            $meta_title = '编辑分类';
        }
        if($pid){
            $pMap['id'] = $pid;
            $pMap['store_id'] = $this->store_id;
            $pMap['status'] = array('egt',0);
            $data['pname'] = $model->where($pMap)->getField('name');
            $pid = $data['pname'] ? $pid : 0;
        }
        $this->assign('pid',$pid);
        $this->assign('data',$data);
        $this->assign('meta_title',$meta_title);
        $this->display();
    }
    
    
    /**
     * 删除商户导航
     */
    public function delClass(){
        $id = I('request.ids');
        if(empty($id)){
            $this->error('请选择要操作的对象');
        }
        $map['id'] = array('in',$id);
        $map['store_id'] = $this->store_id;
        $rst = M('StoreClass')->where($map)->delete();
        if($rst !== false){
            //删除下面的分类
            M('StoreClass')->where(array('pid'=>$id,'store_id'=>$this->store_id))->delete();
        }
        $rst ? $this->success('成功删除') : $this->error('删除失败！');
    }
    
    
    /**
     * 卖家发货地址
     */
    public function address(){
        $map['store_id'] = $this->store_id;
        // 发货地址列表
        $order = '`is_default` DESC';
        $lists = $this->lists(M('StoreAddress'), $map,$order);
        $this->assign('lists',$lists);
        $this->display();
    }
    
    
    /**
     * 编辑、新增卖家发货地址
     */
    public function editAdd(){
        $id = I('request.id');
        $map['id'] = $id;
        $map['store_id'] = $this->store_id;
        $model = M('StoreAddress');
        if(IS_POST && IS_AJAX){
            $data['id'] = $id;
            $data['store_id'] = $this->store_id;
            //省市区处理
            $data['province'] = I('province');
            $data['city'] = I('city');
            $data['district'] = I('district');
            if(empty($data['province']) || empty($data['city']) || empty($data['district'])){
                $this->error('请填写省市区');
            }
            $aIds[] = $data['province'];
            $aIds[] = $data['city'];
            $aIds[] = $data['district'];
            $data['area'] = D('Area')->strArea($aIds);
            $data['seller_name'] = I('name');
            $data['telphone'] = I('tel');
            $data['address'] = I('address');
            $data['company'] = I('company');
            empty($data['seller_name']) && $this->error('请填写联系人');
            //验证电话号或者手机号码 非空验证 正则验证
            empty($data['telphone']) && $this->error('请填写手机号');
            if (!preg_match('/(^(0{1}\d{2,3}-)?\d{7,8})$|(1[34578]{1}[0-9]{9})/',$data['telphone'])) {
                $this->error('请填写正确格式的手机号码或者固话');
            }
            empty($data['address']) && $this->error('请填详细地址');
            
            if(!empty($id)){
                $type = '编辑';
                $rst = $model->where($map)->save($data);
            }else{
                $type = '添加';
                $rst = $model->add($data);
            }
            $rst !== false ? $this->success($type.'成功！',U('address')) : $this->error($type.'失败！');
        }
        $data = array();
        $meta_title = '添加地址';
        if($id){
            $data = $model->where($map)->find();
            $meta_title = '编辑地址';
        }
        $this->assign('data',$data);
        $this->assign('meta_title',$meta_title);
        $this->display();
    }
    
    
    /**
     * 删除商户导航
     */
    public function delAdd(){
        $id = I('request.ids');
        if(empty($id)){
            $this->error('请选择要操作的对象');
        }
        $map['id'] = array('in',$id);
        $map['store_id'] = $this->store_id;
        $rst = M('StoreAddress')->where($map)->delete();
        $rst ? $this->success('成功删除') : $this->error('删除失败！');
    }
    
    /**
     * 品牌申请
     */
    function brand(){
        $name = I('get.name');
        $cid = I('get.cid');
        $status = I('get.status');
        $map['status'] = array('egt',0);
        $map['store_id'] = $this->store_id;
        $name && $map['name'] = $name;
        $cid && $map['cid'] = $cid;
        if(isset($_GET['status']) && $status >= 0){
            $map['status'] = $status;
        }
        $order = '`id` ASC';
        $lists = $this->lists('Brand', $map,$order);
        int_to_string($lists, array('status' => array('0' => '<span class="text-cancel">待审核</span>', '1' => '<span class="text-success">审核通过</span>')));
        //分类查询
        $cMap['pid'] = 0;
        $cMap['is_display'] = 1;
        $cMap['status'] = 1;
        $tmpData = M('ItemCategory')->where($cMap)->limit(100)->select();
        $class = array();
        foreach ($tmpData as $key=>$val){
            $class[$val['id']] = $val;
        }
        //记录当前列表页的Cookie
        Cookie('__forward__', $_SERVER['REQUEST_URI']);
        $this->assign('lists',$lists);
        $this->assign('class',$class);
        $this->meta_title = '品牌列表';
        $this->display();
    }
    
    
    /**
     * 编辑、新增品牌
     */
    public function brandEdit(){
        $id = I('request.id');
        $model = M('brand');
        $map['id'] = $id;
        $map['store_id'] = $this->store_id;
        if(IS_POST && IS_AJAX){
            $id = I('id');
            $saveData['name'] = I('name');
//            $saveData['cid'] = I('cid_3') ? I('cid_3') : (I('cid_2') ? I('cid_2') : I('cid_1'))  ;
            $saveData['cid'] = I('cid_1')  ;
            $saveData['pic'] = I('pic');
            $saveData['store_id'] = $this->store_id;
            $saveData['letter'] = getLetter($saveData['name']);
            if(empty($saveData['name'])){
                $this->error('品牌名称必须填写');
            }
            if(empty($saveData['cid'])){
                $this->error('品牌分类必须选择');
            }
            if(empty($saveData['pic'])){
                $this->error('品牌图片必须上传');
            }
    
            if(!empty($id)){
                //查看是否已审核通过
                $info = $model->where($map)->find();
                if(!$info){
                    $this->error('此品牌删除！');
                }
                if($info['status'] > 0){
                    $this->error('此品牌已审核通过！');
                }
                $rst = $model->where($map)->save($saveData);
                $type = '编辑';
            }else{
                $rst = $model->add($saveData);
                $type = '新增';
            }
            ($rst !== false) ? $this->success($type.'成功', U('Store/brand') ) : $this->error($type.'失败');
            exit;
        }
        $data = array();
        //分类查询
        $cMap['pid'] = 0;
        $cMap['is_display'] = 1;
        $cMap['status'] = 1;
        $class = M('ItemCategory')->where($cMap)->limit(100)->select();
        if(!empty($id)){
            $meta_title = '编辑品牌';
            $data = $model->where($map)->find();
            $tree = M('ItemCategory')->where('id ='.$data['cid'])->getField('trees');
            $cids = explode(',' ,$tree );
            $cids = array_filter($cids);
            sort($cids);
            if($cids[0])$this->cid_1 = $cids[0];
            if($cids[1])$this->cid_2 = $cids[1];
            if($cids[3])$this->cid_3 = $cids[2];
        }else{
            $meta_title = '新增品牌';
        }
        $this->assign('class',$class);
        $this->assign('data',$data);
        $this->assign('meta_title',$meta_title);
        $this->display();
    }
    
    
    /**
     * 删除品牌
     */
    public function delBrand(){
        $id = I('request.ids');
        if(empty($id)){
            $this->error('请选择要操作的对象');
        }
        $map['id'] = array('in',$id);
        $rst = M('Brand')->where($map)->delete();
        $rst ? $this->success('成功删除') : $this->error('删除失败！');
    }
    
    
    /**
     * 店铺消息列表
     */
    public function message($keywords=''){
        $type = I('type', 'all');
        $map = array(
            'title|content' => array('LIKE', '%'.trim($keywords).'%'),
            'store_id' => $this->store_id,
            'type' => $type
        );
        $lists = A('Store', 'Event')->msgLists($map);
        $this->assign('type',$type);
        $this->assign('lists',$lists);
        $this->display();
    }
    
    
    /**
     * 消息详情
     */
    public function detailMsg(){
        $message_id = I('get.id', 0 , 'intval');
        if(empty($message_id)){
            $this->error('参数异常');
        }
        $where = A('Store', 'Event')->getWhereArray($this->store_id);
        $data = M('StoreMessage')->field('id,uid, title, content, ctime')->where($where)->getById($message_id);
        if(empty($data)){
            $this->error('消息不存在！');
        }
        $data['content'] = nl2br(text2links($data['content']));
        $data['ctime'] = time_format($data['ctime']);
        //改为已读
        $save['store_id'] = $this->store_id;
        $save['message_id'] = $message_id;
        $save['read_time'] = NOW_TIME;
        $result = M('StoreMessageRecord')->where("message_id='{$message_id}' and store_id='{$this->store_id}'")->field('id')->find();
        if(!$result || !isset($result['id'])){
            M('StoreMessageRecord')->add($save);
        }
        
        $this->assign('data',$data);
        $this->assign('meta_title','消息详情');
        $this->display();
    }
    
    
    /**
     * 读取、设置消息
     */
    public function setMsg(){
        $id = I('get.id');
        $delete = I('get.del');
        if(empty($id)){
            $this->error('参数错误');
        }
        $map = array(
            'store_id' => $this->store_id,
            'message_id' => $id
        );
        $model = M('StoreMessageRecord');
        $record_id = $model->where($map)->getField('id');
        if($delete == 1){
            $map['status'] = -1;
        }
        if(!$record_id){
            $map['read_time'] = NOW_TIME;
            $record_id = $model->add($map);
        }elseif(isset($map['status'])){
            $model->where('id='.$record_id)->save($map);
        }
        $this->success('操作成功！');
    }

    public function setMsgStatus(){
        $message_id = array_unique((array) I('id', 0));
        $store_id = $this->store_id;
        if(empty($message_id)){
            $this->error('请选择要操作的数据!');
        }
        foreach($message_id as $value){
            $result = M('StoreMessageRecord')->where("message_id='{$value}' and store_id='{$store_id}'")->field('id')->find();
            if(!$result || !isset($result['id'])){
                $save['store_id'] = $store_id;
                $save['message_id'] = $value;
                $save['read_time'] = NOW_TIME;
                M('StoreMessageRecord')->add($save);
            }
        }
        $message_id = is_array($message_id) ? implode(',', $message_id) : $message_id;
        $map['message_id'] = array('in',$message_id);
        $map['store_id'] = $store_id;
        $status = M('StoreMessageRecord')->where($map)->setField('status',-1);
        $status > 0 ? $this->success('删除成功') : $this->error('删除失败');
    }
    
    /**
     *  店铺地址修改申请
     */
    public function editAddress(){
        $member_id = $_SESSION['jipushop_store']['seller_user']['member_id'];
        //查询店铺原来信息
        $data = M('StoreApply')->where('member_id='.$member_id)->Field('company_address AS address,company_address_detail AS address_info')->find();
        //查询是否申请
        $res = M('Store_edit_address')->where('member_id='.$member_id)->find();
        if (IS_POST) {
            //数据
            $province = $this->_getAreaName(I('post.province'));
            $district = $this->_getAreaName(I('post.district'));
            $city     = M('Area')->getFieldById(I('post.city'),'title');
            $address  = $province.' '.$district.' '.$city; 

            $cdata['address'] = $address;
            //$cdata['address'] = I('post.address');
            $cdata['address_detail'] = I('post.address_detail');
            $cdata['create_time'] = NOW_TIME;
            $cdata['status'] = 0;
            //判断是否填写
            if (empty($cdata['address'])) {
               $this->error('店铺所在地不能为空！');
            }
            if (empty($cdata['address_detail'])) {
               $this->error('店铺详情地址不能为空！');
            }
            //地址未发生改变
            if ( ($data['address'] == $cdata['address']) && ($data['address_info'] == $cdata['address_detail'])) {
                $this->error('地址未发生变化！');
            }else{
                $store = M('Store_edit_address');
                //判断以前是否申请过 ，申请过修改数据
                if (isset($res)) {
                    $cdata['update_time'] = '';
                    if($store->where('member_id='.$member_id)->save($cdata)){
                        $this->success('店铺地址修改申请成功');
                    }else{
                        $this->error('店铺地址修改申请失败');
                    }
                }else{
                    $cdata['member_id'] = $member_id;
                    if($store->data($cdata)->add()){
                        $this->success('店铺地址修改申请成功');
                    }else{
                        $this->error('店铺地址修改申请失败');
                    }
                }
                
            }
        }
        $this->meta_title='店铺地址修改申请';
        //省市区数据修改
        $area = explode(' ',$data['address']);
        $arr['province'] = $this->_getAreaId($area[0]);
        $arr['district'] = $this->_getAreaId($area[1]);
        $arr['city'] = M('Area')->getFieldByTitle($area[2],'id');
        //查询商店经纬度
        $latlng = getStoreLatLng($member_id);
        $this->latlng = $latlng;
        $this->arr = $arr;
        $this->data = $data;
        if (isset($res)) {
            //后台限制修改时间
            $limit_time = NOW_TIME - C('EDIT_STORE_ADDRESS_TIME') * 86400;
            //首先判断申请是否处于待审核状态 是：不允许再次申请
            if ($res['status'] == 0) {
               $this->status = $res['status'];
                $this->info = $res;
            }else{
                //时间判断
                if ($res['create_time'] > $limit_time) {
                    $this->status = $res['status'];
                    $this->info = $res;
                }else{
                    $this->status = 3;
                }
            }
        }else{
            $this->status = 3;
        }
        $this->display();
    }

    /**
     * 获取省市区ID
     * @author buddha <[email address]>
     * @return [type] [description]
     */
    private function _getAreaId($name){
        return M('Area')->getFieldBySubName($name,'id');
    }

    /**
     * 获取省市区名称
     * @author buddha <[email address]>
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    private function _getAreaName( $id ){
        return M('Area')->getFieldById($id,'sub_name');
    }

    /**
     * 通过经纬度获取具体地址
     * @author buddha <[email address]>
     * @return [type] [description]
     */
    function getAddresInfoByLngLat(){
        $lat = I('post.lat');
        $lng = I('post.lng');
        //调用函数
        $res = getLocationLatLng($lat,$lng);
        $this->ajaxReturn($res);
    }

    /**
     * 商户修改后台登陆密码 20170622
     * @author buddha <[email address]>
     * @return [type] [description]
     */
    public function updatePassword(){
        if (IS_POST) {
            //修改密码
            $password = I('post.old');
            empty($password) && $this->error('请输入原密码');
            $data['password'] = I('post.password');
            empty($data['password']) && $this->error('请输入新密码');
            $repassword = I('post.repassword');
            empty($repassword) && $this->error('请输入确认密码');
            if($data['password'] !== $repassword){
              $this->error('您输入的新密码与确认密码不一致');
            }
            $user_api = new UserApi();
            $uid = $_SESSION['jipushop_store']['seller_user']['member_id'];
            $res = $user_api->updateInfo($uid, $password, $data);
            if($res['status']){
                session('seller_user',null);//清空session
                $this->success('密码修改成功！', U('login'));
            }else{
                $this->error($res['info']);
            }
            
        }
        $this->meta_title='商户修改后台登陆密码';
        $this->display();
    }
}   
